package com.xxg.oauth2.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Configuration
public class WebConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    LogoutHandler logoutHandler;


    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable()
                .logout()
                .logoutSuccessHandler(logoutHandler)
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .and()
                .authorizeRequests()
                .antMatchers("/login/**")
                .permitAll()
                // 其他所有请求需要身份认证
                .anyRequest().authenticated()
                // 配置登录认证
                .and().formLogin().loginProcessingUrl("/login");
    }



    public static void main(String...args) {
        List<String> list = new ArrayList<String>();
        list.add("I am a boy");
        list.add("I love the girl");
        list.add("But the girl loves another girl");

        Integer[] i = new Integer[]{1,2,3,4,5,6};
        List<Integer> l1  = Arrays.asList(i);

        list.stream()
                .map(l -> {
                    return "null";
                }).forEach(System.out::println);

        int age = l1.stream().reduce(0, Integer::sum);
        System.out.println(age);

    }
}
